import store from '~/store';
import {saveUserInfo} from '~/store/userinfo';
import {logout} from '~/api/user';

export const logoutAccount = async () => {
    const result = await logout();
    if (result.code === 0) {
        const userinfo = {
            userid: 0,
            owner: 0,
            ownername: '',
            company: 0,
            companyname: '',
            bank: 0,
            bankname: '',
            agent: 0,
            agentname: '',
            staff: 0,
            staffname: '',
            mobile: '',
            identityname: '',
            logo: '',
            nickname: '',
            token: '',
            code: '',
        };
        store.dispatch(saveUserInfo(userinfo));
        const getter = store.getState();
        const navigation = getter.system.msgNav;
        navigation.setParams({count: 0});
        return true;
    } else {
        return false;
    }
};
